* Use data from the ANES 2020 Time Series Study
* https://electionstudies.org/data-center/2020-time-series-study/


use "anes_timeseries_2020_stata_20210719.dta"

* Figure 1 outcome

tab V202338
recode V202338 (-9/-1=.) (1=5) (2=4) (3=3) (4=2) (5=1), gen(gunLEVEL)
tab V202338 gunLEVEL, mi

* Figure 2 outcome

tab V202338
recode V202338 (-9 2/5=0 "Residual") (1=1 "Extremely important") (-8/-5=.), gen(gunIMP)
tab V202338 gunIMP, mi

* Partisanship

tab V201231x 
clonevar party7 = V201231x 
recode party7 (-9/-1=.)
tab V201231x party7, mi

* Controls

tab V201600
recode V201600 (-9/-1=99), gen(gender)
tab V201600 gender, mi

tab V201549x
recode V201549x (-9/-1=99), gen(race)
tab V201549x race, mi

tab V201507x
recode V201507x (-9=.), gen(age)
recode V201507x (-9=99) (18/29=1) (30/39=2) (40/49=3) (50/59=4) (60/69=5) (70/79=6) (80=7), gen(ageGRP)
tab V201507x ageGRP, mi

tab V201511x
recode V201511x (-9/-1=99), gen(educ)
tab V201511x educ, mi

tab V201508
recode V201508 (-9/-8=99) (2=1), gen(marital)
tab V201508 marital, mi

tab V201617x
recode V201617x (-5=99) (-9=99), gen(income)
tab V201617x income, mi

tab V201628
recode V201628 (1/99=1 "1+ guns") (0=0 "Zero guns") (-9=99 "Refused") (-5=.), gen(gunOWN)
tab V201628 gunOWN, mi

* Analyses

svyset [pweight=V200010b], strata(V200010d) psu(V200010c)
desc V200010b V200010d V200010c
codebook party7

svy: reg gunLEVEL party7 i.gender i.race i.ageGRP i.educ i.marital i.income i.gunOWN
margins, atmeans at(party7=(1(1)7)) noatlegend
marginsplot

svy: reg gunIMP i.party7 i.gender i.race i.ageGRP i.educ i.marital i.income i.gunOWN, level(83.4)
margins, atmeans at(party7=(1(1)7)) noatlegend
marginsplot, level(83.4)
